﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SimpleItems_Animator : InteractiveItems
{
    /// <summary>
    /// 动画器
    /// </summary>
    [SerializeField] protected Animator animator;
    /// <summary>
    /// 交互动画播放时间
    /// </summary>
    [SerializeField]protected float animationTime = 0.35f;

    /// <summary>
    /// 加载基本组件
    /// </summary>
    protected override void Awake()
    {
        base.Awake();
        if (animator==null)
        {
            animator = GetComponent<Animator>();
        }
        
    }

    /// <summary>
    /// 进行交互会触发"change"Tagger
    /// </summary>
    public override void Interactive()
    {
        base.Interactive();
        PlayAnimator();
        OnAnimationStart();
        Invoke("OnAnimationEnd", animationTime);
    }

    /// <summary>
    /// 触发"change"Tagger
    /// </summary>
    protected virtual void PlayAnimator()
    {
        animator.SetTrigger("change");
    }

    /// <summary>
    /// 交互动画开始时调用
    /// </summary>
    protected virtual void OnAnimationStart()
    {

    }

    /// <summary>
    /// 交互动画结束时调用
    /// </summary>
    protected virtual void OnAnimationEnd()
    {

    }
}
